﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class san_pham : System.Web.UI.Page
{
    Tour Tour;
    List<ObjTour> lstObjTour;
    protected string ten_loai_tour;
    LoaiTour loaiTour;
    ObjLoaiTour objLoaiTour;
    protected void Page_Load(object sender, EventArgs e)
    {

        loaiTour = new LoaiTour();
        datalist_conten.ItemDataBound += new DataListItemEventHandler(datalist_conten_ItemDataBound);
        //tim kiem san pham
        if (Request.QueryString["text"] != null || Request.QueryString["text1"] != null)
        {
            Tour = new Tour();
            lstObjTour = new List<ObjTour>();
            if (Request.QueryString["text"] != null)
            {
                lstObjTour = Tour.getTourBySearch(Request.QueryString["text"].ToString());
            }
            else
            {
                lstObjTour = Tour.getTourBySearch1(Request.QueryString["text1"].ToString(), Request.QueryString["giatu"].ToString(), Request.QueryString["giaden"].ToString());
            }
            Page.Title = "Tìm kiếm tour";
            ten_loai_tour = "Kết quả tìm kiếm";        
                if (lstObjTour.Count > 0)
                {
                    CollectionPager1.DataSource = lstObjTour;
                    CollectionPager1.BindToControl = datalist_san_pham;
                    datalist_san_pham.DataSource = CollectionPager1.DataSourcePaged;


                }
                else
                    lb_messenger.Text = "Không có tour";
            }
        //if (Request.QueryString["text1"] != null && Request.QueryString["giatu"] != null && Request.QueryString["giaden"] != null)
        //{
        //    Tour = new Tour();
        //    lstObjTour = new List<ObjTour>();
        //    lstObjTour = Tour.getTourBySearch1(Request.QueryString["text1"].ToString(), Request.QueryString["giatu"].ToString(), Request.QueryString["giaden"].ToString());
        //    Page.Title = "Tìm kiếm tour";
        //    ten_loai_tour = "Kết quả tìm kiếm";
        //    if (lstObjTour.Count > 0)
        //    {
        //        CollectionPager1.DataSource = lstObjTour;
        //        CollectionPager1.BindToControl = datalist_san_pham;
        //        datalist_san_pham.DataSource = CollectionPager1.DataSourcePaged;


        //    }
        //    else
        //        lb_messenger.Text = "Không có tour";
        //}
        

            else
            {
                if (Request.QueryString["id"] == null)
                {

                    datalist_conten.DataSource = loaiTour.getDanhMucTour(Constants.HIEN_DANH_MUC_SAN_PHAM);
                    datalist_conten.DataBind();
                    Page.Title = "Chi tiết tour";
                    lb_ten_loai_san_pham.Visible = false;
                }
                else
                {
                    objLoaiTour = loaiTour.getLoaiTourById(Request.QueryString["id"].ToString());
                    ten_loai_tour = objLoaiTour.Ten_loai_tour;
                    Page.Title = objLoaiTour.Ten_loai_tour;
                    Tour = new Tour();
                    lstObjTour = new List<ObjTour>();
                    lstObjTour = Tour.getTourByLoaiTourId(Request.QueryString["id"].ToString(), Constants.ALL);
                    if (lstObjTour.Count > 0)
                    {
                        CollectionPager1.DataSource = lstObjTour;
                        CollectionPager1.BindToControl = datalist_san_pham;
                        datalist_san_pham.DataSource = CollectionPager1.DataSourcePaged;

                    }
                    else
                    {
                        lb_messenger.Text = "Không có tour";
                    }
                }
            }

        }
    
        
    
        

    void datalist_conten_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        DataList datalist = (DataList) e.Item.FindControl("datalist_san_pham");

        String loai_tour_id = DataBinder.Eval(e.Item.DataItem, "loai_tour_id").ToString();
        Tour = new Tour();
        lstObjTour = new List<ObjTour>();
        lstObjTour = Tour.getTourByLoaiTourId(loai_tour_id, Constants.TOP);
        if (lstObjTour.Count > 0)
        {
            datalist.DataSource = lstObjTour;
            datalist.DataBind();
        }
        else
        {
            e.Item.FindControl("lb_ten_loai_san_pham").Visible=false;
            e.Item.FindControl("lb_xem_tat").Visible = false;
        }
    }
}